﻿using AmuTools;
using app.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace app.Models
{
    [Model(TableName = "t_step", PrimaryKey = "id", IdentityInsert = true)]
    public class Step
    {
        [Field(Description = "唯一标识符")]
        public int id { get; set; }


        [Field(Description = "模板ID")]
        public int template_id { get; set; }


        [Field(Description = "服务项目ID")]
        public int service_id { get; set; }


        [Field(Description = "步骤号")]
        public int number { get; set; }


        [Field(Description = "步骤标题")]
        public string title { get; set; }


        [Field(DataType = "text", Description = "步骤介绍")]
        public string content { get; set; }


        [Field(DataType = "text", Description = "备注")]
        public string remark { get; set; }


        [Field(Description = "逗号分隔的附件ID数组")]
        public string appendix_ids { get; set;}


        [Field(Storageable = false, Description = "附件数组")]
        public List<UploadedFile> appendix
        {
            get
            {
                if (appendix_ids == "") return new List<UploadedFile>();
                else
                {
                    string condition = string.Format("{0} in ({1})", G.DB.GetPrimaryKey<UploadedFile>(), appendix_ids);
                    return G.DB.Get<UploadedFile>(condition).GetFirstTableList<UploadedFile>();
                }
            }
        }


        [Field(Description = "是否允许需求方上传")]
        public int allow_demand_upload { get; set; }


        [Field(Description = "是否允许审核阶段修改")]
        public int allow_checking_modify { get; set; }


        // 获取某个服务的所有步骤
        public static List<Step> GetSteps(int service_id)
        {
            return G.DB.Get<Step>(string.Format("service_id={0}", service_id), "number asc").GetFirstTableList();
        }
    }
}